// LoggerAPI.h : Include file for standard system include files,
// or project specific include files.

#pragma once

#include "../3rdparty/include/TokenBucket.h"
#include "../Common/SafeQueue.hpp"
#include "../Common/LogItem.hpp"
#include "../Common/Packet.hpp"
#include "../Common/Codec.hpp"
#include "LogSender.hpp"
#include "LogLocalWriter.hpp"

// TODO: Reference additional headers your program requires here.
namespace cybertron {

enum LOG_LEVEL
{
	LOG_LEVEL_DEBUG,
	LOG_LEVEL_INFO,
	LOG_LEVEL_WARN,
	LOG_LEVEL_ERROR,
	LOG_LEVEL_FATAL
};

class LogApiImpl
{
public:
	LogApiImpl();
	~LogApiImpl();

	int set_rate_limit(uint64_t rate_per_sec, uint64_t burst_size);

	int enable_net_appender(const std::string &ip, unsigned short port);
	int enable_console_appender();
	int enable_file_appender(const std::string &file_path);

	void log(LOG_LEVEL level, const char *category, const char *producer, const char *message);

	static LogApiImpl *_instance;

private:
	bool _net_appender_enabled;
	mutable std::mutex _lock;
	LogSender *_log_sender;
	MsgEncoder *_log_encoder;
	LogLocalWriter *_log_local_writer;
	//std::string _default_category;
	SafeQueue<LogItem> *_item_remote_queue;
	SafeQueue<LogItem> *_item_local_queue;
	SafeQueue<NetPacket> *_packet_queue;
	TokenBucket _token_bucket;
	bool _has_rate_limit;
	static std::string level_to_string(LOG_LEVEL level);
};

}
